import { defineConfig,loadEnv ,ConfigEnv,UserConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import path from "path"
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import Icons from "unplugin-icons/vite";
import IconsResolver from "unplugin-icons/resolver";
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
import UnoCSS from 'unocss/vite'
const pathSrc = path.resolve(__dirname,"src")
export default defineConfig(({ mode }: ConfigEnv): UserConfig=>{
  const env = loadEnv(mode,process.cwd())
  return {
  resolve:{
    alias:{
      "@": pathSrc
    }
  },
  css: {
    preprocessorOptions: {
        scss: {
            javascriptEnabled: true,
            additionalData: `@use "@/styles/variables.scss" as *;`
        }
    }
  },
  plugins: [
    vue(),
    AutoImport({
      imports: ["vue"],
      eslintrc: {
        enabled: true, 
        filepath: "./.eslintrc-auto-import.json",
      },
      dts: path.resolve(pathSrc, "types", "auto-imports.d.ts"), 
    }),
    Components({
      resolvers: [
        ElementPlusResolver(),
        IconsResolver({
          enabledCollections: ["ep"] 
        }),
      ],

      dts: path.resolve(pathSrc, "types", "components.d.ts"), 
    
    }),
    Icons({

      autoInstall: true,
    }),
    createSvgIconsPlugin({
      iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
      symbolId: 'icon-[dir]-[name]',
  }),
   UnoCSS({ /* options */ }),
],

  base:"./",
  server:{
    host:"0.0.0.0",
    port:3000,
    // open:true, 
    proxy: {
      '/api': {
        // target: 'http://192.168.10.1:8001',
        target: "http://192.168.5.74:3001",
        // target: "http://localhost:3001",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      },
    },
  }
  }
})
